﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using TerryDong.Core;
namespace WebApp
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class OutputHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request["source"] == "JqueryListPager")
            {
                BuildDemoData(context);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public void BuildDemoData(HttpContext context)
        {
            demoModel d = new demoModel();
            d.status = 0;
            d.count = 500;
            for (int i = 0; i < 500; i++)
            {
                d.items.Add(new itemModel(){ id=i,name="name"+i.ToString(), amount=100+i, create_date=System.DateTime.Now});
            }

           context.Response.Write(d.ToJson());
        }

        public class demoModel
        {
            public int status { get; set; }
            public int count { get; set; }

            public List<itemModel> items = new List<itemModel>();
        }

        public class itemModel
        {
            public int id { get; set; }
            public string name { get; set; }
            public decimal amount { get; set; }
            public DateTime create_date { get; set; }
        }
    }
}
